package com.link2room.ironhide.controller.inside;


import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.dto.result.base.HotelBaseInfoDto;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.common.util.StringUtil;
import com.link2room.ironhide.dto.param.inside.HotelBaseInfoInsideParamDto;
import com.link2room.ironhide.dto.result.base.L2RHotelPictureDto;
import com.link2room.ironhide.facade.IHotelInfoFacadeService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by sss on 2016/8/26.
 */
@Api(tags = "酒店基础信息相关")
@RestController
@RequestMapping("/in/HotelBaseInfos")
public class HotelBaseInfoInsideController {
    @Resource
    private IHotelInfoFacadeService hotelInfoFacadeService;

    @RequestMapping(method= RequestMethod.GET)
    public BaseResultDto hotelBaseInfoList(
            @RequestParam(value = "lhotelCode" ,required = false) String lhotelCode,
            @RequestParam(value = "province" ,required = false) Long province,
            @RequestParam(value = "city" ,required = false) Long city,
            @RequestParam(value = "district" ,required = false) Long district,
            @RequestParam(value = "brands" ,required = false) String brands,
            @RequestParam (value = "status" ,required = false) String status
    ) throws Exception {
        List<String> brandList=new ArrayList();
        if(StringUtil.isNotBlank(brands)){
            String[] brandArr = brands.split(",");
            for(String brand:brandArr){
                brandList.add(brand);
            }
        }

        HotelBaseInfoInsideParamDto hotelBaseInfoInsideParamDto =new HotelBaseInfoInsideParamDto();
        hotelBaseInfoInsideParamDto.setLhotelCode(lhotelCode);
        hotelBaseInfoInsideParamDto.setCity(city);
        hotelBaseInfoInsideParamDto.setDistrict(district);
        hotelBaseInfoInsideParamDto.setProvince(province);
        hotelBaseInfoInsideParamDto.setStatus(status);
        hotelBaseInfoInsideParamDto.setBrands(brandList);
        QueryResult<HotelBaseInfoDto> hotelBaseInfoResult = hotelInfoFacadeService.listHotelBaseInfo(hotelBaseInfoInsideParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(hotelBaseInfoResult);
        return l2rRs;
    }

    @RequestMapping(value = "/{id}",method= RequestMethod.GET)
    public BaseResultDto hotelBaseInfo(
            @PathVariable Long id
    ) throws Exception {
        HotelBaseInfoInsideParamDto hotelBaseInfoInsideParamDto =new HotelBaseInfoInsideParamDto();
        hotelBaseInfoInsideParamDto.setId(id);
        HotelBaseInfoDto hotelBaseInfo = hotelInfoFacadeService.getHotelBaseInfo(hotelBaseInfoInsideParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(hotelBaseInfo);
        return l2rRs;
    }

    @RequestMapping(value = "/HotelBaseInfo",method= RequestMethod.GET)
    public BaseResultDto hotelBaseInfoByLhotelCode(
            @RequestParam(value = "lhotelCode" ,required = false) String lhotelCode
    ) throws Exception {
        HotelBaseInfoInsideParamDto hotelBaseInfoInsideParamDto =new HotelBaseInfoInsideParamDto();
        hotelBaseInfoInsideParamDto.setLhotelCode(lhotelCode);
        HotelBaseInfoDto hotelBaseInfo = hotelInfoFacadeService.getHotelBaseInfo(hotelBaseInfoInsideParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(hotelBaseInfo);
        return l2rRs;
    }

    @RequestMapping(value = "/HotelBigPics",method= RequestMethod.GET)
    public BaseResultDto hotelBigPics(
            @RequestParam(value = "lhotelCodes" ,required = false) String lhotelCodes
    ) throws Exception {
        List<String> lhotelCodeList=new ArrayList();
        if(StringUtil.isNotBlank(lhotelCodes)) {
            String[] lhotelCodeArr = lhotelCodes.split(",");
            for (String lhotelCode : lhotelCodeArr) {
                lhotelCodeList.add(lhotelCode);
            }
        }
        HotelBaseInfoInsideParamDto hotelBaseInfoInsideParamDto =new HotelBaseInfoInsideParamDto();
        hotelBaseInfoInsideParamDto.setLhotelCodes(lhotelCodeList);
        QueryResult<L2RHotelPictureDto> hotelBigPicResult = hotelInfoFacadeService.getHotelBigPic(hotelBaseInfoInsideParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(hotelBigPicResult);
        return l2rRs;
    }

    @RequestMapping(value = "/HotelPics",method= RequestMethod.GET)
    public BaseResultDto hotelPics(
            @RequestParam(value = "lhotelCodes" ,required = false) String lhotelCodes
           ) throws Exception {
        List<String> lhotelCodeList=new ArrayList();
        if(StringUtil.isNotBlank(lhotelCodes)) {
            String[] lhotelCodeArr = lhotelCodes.split(",");
            for (String lhotelCode : lhotelCodeArr) {
                lhotelCodeList.add(lhotelCode);
            }
        }
        HotelBaseInfoInsideParamDto hotelBaseInfoInsideParamDto =new HotelBaseInfoInsideParamDto();
        hotelBaseInfoInsideParamDto.setLhotelCodes(lhotelCodeList);
        QueryResult<L2RHotelPictureDto> hotelBigPicResult = hotelInfoFacadeService.getHotelPics(hotelBaseInfoInsideParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(hotelBigPicResult);
        return l2rRs;
    }
}
